#include "ros/ros.h"
#include "tf2_ros/static_transform_broadcaster.h"
#include "geometry_msgs/TransformStamped.h"
#include "tf2/LinearMath/Quaternion.h"

int main(int argc, char  *argv[])
{
    setlocale(LC_ALL,"");
    ros::init(argc,argv,"static_pub");
    ros::NodeHandle nh;

    //创建发布者对象，tf静态坐标下的发布者用tf2_ros下的对象
    tf2_ros::StaticTransformBroadcaster pub;

    //组织被发布的消息
    geometry_msgs::TransformStamped tf;
    tf.header.stamp = ros::Time::now();//获取当前时间戳
    tf.header.frame_id = "base_link";//相对坐标中被参考的
    tf.child_frame_id = "laser";//相对坐标中参考别人的
    //子偏离父多少
    tf.transform.translation.x = 0.2;
    tf.transform.translation.y = 0.0;
    tf.transform.translation.z = 0.5;
    //四元数，要通过欧拉角转换
    tf2::Quaternion q;//利用该对象将欧拉角转换成四元数
    q.setRPY(0,0,0);//输入欧拉角参数
    tf.transform.rotation.x = q.getX();
    tf.transform.rotation.y = q.getY();
    tf.transform.rotation.z = q.getZ();
    tf.transform.rotation.w = q.getW();
    
    //发布数据
    pub.sendTransform(tf);

    ros::spin();
    return 0;
}
